package com.module.wx.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.module.wx.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.module.wx.domain.ZzdHorsemanOrderListInfo;
import com.module.wx.service.IZzdHorsemanOrderListInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author hezhengxian
 * @date 2023-03-06
 */
@RestController
@RequestMapping("/horsemanOrderList")
public class ZzdHorsemanOrderListInfoController extends BaseController
{
    @Autowired
    private IZzdHorsemanOrderListInfoService zzdHorsemanOrderListInfoService;

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("wx:horsemanOrderList:list")
    @GetMapping("/list")
    public TableDataInfo list(ZzdHorsemanOrderListInfo zzdHorsemanOrderListInfo)
    {
        startPage();
        List<ZzdHorsemanOrderListInfo> list = zzdHorsemanOrderListInfoService.selectZzdHorsemanOrderListInfoList(zzdHorsemanOrderListInfo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("wx:horsemanOrderList:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZzdHorsemanOrderListInfo zzdHorsemanOrderListInfo)
    {
        List<ZzdHorsemanOrderListInfo> list = zzdHorsemanOrderListInfoService.selectZzdHorsemanOrderListInfoList(zzdHorsemanOrderListInfo);
        ExcelUtil<ZzdHorsemanOrderListInfo> util = new ExcelUtil<ZzdHorsemanOrderListInfo>(ZzdHorsemanOrderListInfo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @RequiresPermissions("wx:horsemanOrderList:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(zzdHorsemanOrderListInfoService.selectZzdHorsemanOrderListInfoById(id));
    }

    /**
     *  骑手接单操作
     */
    @RequiresPermissions("wx:horsemanOrderList:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addReceivingOrders")
    public AjaxResult addReceivingOrders(@RequestBody ZzdHorsemanOrderListInfo zzdHorsemanOrderListInfo)
    {
        zzdHorsemanOrderListInfo.setId(Util.get_radom_id());
        // 取餐时间
        zzdHorsemanOrderListInfo.setReceivingOrdersTime(new Date());
        return toAjax(zzdHorsemanOrderListInfoService.insertZzdHorsemanOrderListInfo(zzdHorsemanOrderListInfo));
    }

    /**
     *  骑手存餐操作
     */
    @RequiresPermissions("wx:horsemanOrderList:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addSaveMeals")
    public AjaxResult addSaveMeals(@RequestBody ZzdHorsemanOrderListInfo zzdHorsemanOrderListInfo)
    {
        int count=0;
        // 如果id不为空，则证明骑手已接单取餐
        if(zzdHorsemanOrderListInfo.getId()!=null&&!zzdHorsemanOrderListInfo.getId().equals("")){
            // 在用户下单时赋值餐柜及餐柜编号信息，在骑手存餐成功后，回写存餐时间也可？
            zzdHorsemanOrderListInfo.setSaveMealsTime(new Date());
            count = zzdHorsemanOrderListInfoService.updateZzdHorsemanOrderListInfo(zzdHorsemanOrderListInfo);
        }
        return toAjax(count);
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("wx:info:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZzdHorsemanOrderListInfo zzdHorsemanOrderListInfo)
    {
        return toAjax(zzdHorsemanOrderListInfoService.updateZzdHorsemanOrderListInfo(zzdHorsemanOrderListInfo));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("wx:horsemanOrderList:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(zzdHorsemanOrderListInfoService.deleteZzdHorsemanOrderListInfoByIds(ids));
    }
}
